package org.pezke.akunature.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.pezke.akunature.dao.FBachGroupDao;
import org.pezke.akunature.model.fb.FBachGroup;
import org.springframework.stereotype.Repository;


/**
 * @author igarcia
 */
@Repository("fbGroupDao")
public class FBachGroupDaoHibernate extends GenericDaoHibernate<FBachGroup, Long> implements FBachGroupDao {


	/**
     * Constructor to create a Generics-based version using Role as the entity
     */
    public FBachGroupDaoHibernate() {
        super(FBachGroup.class);
    }
		
	
	/**
	 * Devuelve la lista de grupos a partir de los criterios seleccionados
	 */
	@SuppressWarnings("unchecked")
	public List<FBachGroup> search(FBachGroup criteria) {
		
		Criteria dc = getSession().createCriteria(FBachGroup.class);
		
		if(criteria!=null){
			if(criteria.getName()!=null){
				dc = dc.add(Restrictions.ilike("name", "%" + criteria.getName() + "%"));		
			}
		}
		
		List<FBachGroup> result = dc.list();
		return result;
	}


}
